package com.example.mobile2121606109ycg0407;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivityTip5 extends AppCompatActivity {

    private EditText edtTxtMain5Num;
    private TextView tvMain5Result;
    private Button btnMain5Result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_tip5);
        initView();

        btnMain5Result.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获取输入的数值
                int x = Integer.parseInt(edtTxtMain5Num.getText().toString());
                //分段函数的判断及计算后并输出计算结果
                if(x < 1){
                    tvMain5Result.setText(String.valueOf(x));
                }else if (1 <= x && x <10){
                    x = 2 * x - 1;
                    tvMain5Result.setText(String.valueOf(x));
                }else if (x >= 10){
                    x = 3 * x - 11;
                    tvMain5Result.setText(String.valueOf(x));
                }
            }
        });
    }

    private void initView() {
        edtTxtMain5Num = (EditText) findViewById(R.id.edtTxtMain5_Num);
        tvMain5Result = (TextView) findViewById(R.id.tvMain5_Result);
        btnMain5Result = (Button) findViewById(R.id.btnMain5_Result);
    }
}